package com.bestv.bsr.core.constants;

/**
 * @author taojiacheng
 */

public enum ServiceCodeEnum {
    /**
     * 返回升级包或已经是最新版本
     */
    SUCCESS(0, "成功"),
    SIGN_INVALID(100000, "签名不合法"),
    /**
     * 参数异常
     */
    PARAMETER_INVALID(200000, "参数不合法"),
    ITEM_TYPES_IS_EMPTY(200001, "参数itemTypes为空"),
    SCENE_ID_INVALID(200002, "参数sceneId不合法"),
    SIZE_INVALID(200003, "参数size不合法"),
    ITEM_CODES_IS_EMPTY(200004, "参数itemCodes为空"),
    TV_ID_INVALID(200005, "参数tvId不合法"),
    TV_PROFILE_INVALID(200006, "参数tvProfile不合法"),


    /**
     * 3-xxx-xx:BSR请求后端推荐引擎参数校验异常
     * 3-xxx-xx 3表示bsr到推荐引擎
     * xxx表示驻地 999:通用 000:中台
     */
    MAC_IS_BLANK(320001, "mac为空"),
    SCENE_ID_NOT_SUPPORTED(399901, "sceneId 不支持"),
    ITEM_TYPES_NOT_SUPPORTED(399902, "itemType不支持"),
    USER_ID_IS_BLANK(399903, "百视通账号为空"),
    USER_ACCOUNT_IS_BLANK(399904, "第三方账号为空"),

    METHODTYPE_NOT_SUPPORTED(399905, "推荐方式不支持"),
    AI_SOURCE_NOT_AVAILABLE(399906, "推荐来源不可用"),

    THIRD_PARTY_RESULT_INVALID(900001, "第三方返回结果不合法"),

    // ========================== 其他未知异常 ==========================
    SYSTEM_ERROR(999999, "未知错误");

    private final int code;
    private final String msg;

    ServiceCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ServiceCodeEnum getByCode(int code) {
        for (ServiceCodeEnum serviceCodeEnum : ServiceCodeEnum.values()) {
            if (code == serviceCodeEnum.getCode()) {
                return serviceCodeEnum;
            }
        }
        return SYSTEM_ERROR;
    }


    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
